package com.ruoyi.data.service.impl;

import com.ruoyi.data.domain.*;
import com.ruoyi.data.mapper.DataMapper;
import com.ruoyi.data.service.IDataService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DataServiceImpl implements IDataService {

    @Resource
    private DataMapper mapper;

    @Override
    public int uploadData(DataInfo data) {
        data.setStatus("uploaded");
        return mapper.insertData(data);
    }

    @Override
    public List<DataInfo> listAllData() {
        return mapper.selectAllData();
    }

    @Override
    public int grantPermission(DataPermission permission) {
        permission.setStatus("granted");
        return mapper.insertPermission(permission);
    }

    @Override
    public int revokePermission(Long permissionId) {
        return mapper.revokePermission(permissionId);
    }

    @Override
    public int submitAccessRequest(DataAccessRequest request) {
        request.setStatus("pending");
        return mapper.insertAccessRequest(request);
    }

    @Override
    public int approveRequest(Long requestId) {
        return mapper.updateAccessRequestStatus(requestId, "approved");
    }

    @Override
    public int rejectRequest(Long requestId) {
        return mapper.updateAccessRequestStatus(requestId, "rejected");
    }
}
